package com.itcam.phaseii.exception_;

public class ClassCastException_ {
    public static void main(String[] args) {
        A b = new B();  //向上转型
        B b2 = (B) b;   //向下转型，这里是OK
        try {
            C c2 = (C) b;   //这里抛出ClassCastException
        } catch (java.lang.Exception e) {
//            throw new RuntimeException(e);
            System.out.println("出现异常的类型: " + e.getClass());//输出异常信息
        }
    }
}

class A {
}

class B extends A {
}

class C extends A {
}
